
#include "Hand.h"
#include "Input.h"
#include "Menu.h"

// Function to initialize the hand
void Initialize(hand& h)
{
	card c;
	// Sets the first letter in the "tracking" array to 'A'
	char a = FIRST_CARD;
	// Set the number of card in hand to 0
	h.nbCardInHand = 0;

	// A "For" to remove everything in the hand array
	for (int i = 0; i < NB_MAX_HAND; i++)
	{
		Initialize(c);
		h.cards[i] = c;
	}
	// Initialises the card-choosing-array to show which card is connected to which letter
	for (int j = 0; j < NB_MAX_HAND; j++)
	{
		h.letters[j] = a;
		a++;
	}
}

// Function to discard a card from the player's hand
card Discard(hand& h)
{
	card c;
	int tempCardNumber;
	// roll function to choose a card from the player's hand
	tempCardNumber = ChooseCard(h);
	// Store the int result of the function to place it in the player's hand's table's index
	// And return that card into the "card" variable
	c = h.cards[tempCardNumber];

	// Resort the hand so it doesn't have an empty space.
	for (int i = tempCardNumber; i < h.nbCardInHand; i++)
	{
		h.cards[i] = h.cards[i+1];
	}
	// Remove the last index the of the array.
	h.nbCardInHand--;

	// Returns the resulting card in the function that calls it
	return c;
}

void AddCard(hand& h, card& c)
{
	// Add a card to the hand
	h.cards[h.nbCardInHand] = c;
	h.nbCardInHand++;
}

void Display(const hand& h)
{
	// Displays each card by half until the last one, which is displayed in full
	for (int i = 0; i < CARD_HEIGHT_VISUAL; i++)
	{
		for (int j = 0; j <= h.nbCardInHand; j++)
		{
			if (j == h.nbCardInHand)
			{
				Display(h.cards[j], i, CARD_WIDTH_VISUAL);
			}
			else
			{
				Display(h.cards[j], i, CARD_WIDTH_VISUAL / 2);
			}
		}
		std::cout << std::endl;
	}
	// Displays an array of letters under the cards to show the player
	// which card is associated to which letter
	for (int i = 0; i < ROW_OF_LETTERS; i++)
	{
		for (int j = 0; j <= h.nbCardInHand; j++)
		{
			std::cout << "  " << h.letters[j] << " ";
		}
		std::cout << std::endl;
	}
	
}